package com.example.hotel_demo.mapper;

import com.example.hotel_demo.pojo.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface BookMapper {
    //-------查询全部订单
    @Select("select count(*) from book where bookState!=4 ")
    public int getAllRowsAmount();
    @Select("select * from book  where bookState=0  ORDER BY createTime DESC ")
    public List<Book> getBookAll_weicuoli();
    @Select("select * from book  where bookState!=0 and bookState!=4 ORDER BY createTime DESC ")
    public List<Book> getBookAll_yichuli();

    //通过订单状态-------查询订单
    @Select("select * from book where bookState=#{bookState}")
    public List<Book> getBooksByState(String  bookState);

    //-------------------下未使用---------------------------------------------------------

    //客户user界面使用
    @Select("select * from book where custNum = ${custNum}")
    public List<Book> getBookByCustNum(String custNum);

    @Update("update book set bookTime =#{bookTime} , bookCheckinTime =#{bookCheckinTime} ,bookDay =#{bookDay} ,bookState =#{bookState}  where custNum =#{custNum} ")
    public int updateBookByCustNum(String custNum, Date bookTime, Date bookCheckinTime, int bookDay, int bookState);

    @Insert("insert into book (custNum,roomID,bookTime,bookCheckinTime,bookDay,bookState)" +
            " values(#{custNum},#{roomID},#{bookTime},#{bookCheckinTime},#{bookDay},#{bookState})")
    public int addBook(String custNum, int roomID, Date bookTime, Date bookCheckinTime, int bookDay, int bookState);

    //--------------------上未使用-----------------------------------------------------------
    @Select("select * from book where bookID=#{bookID}")
    public Book getBookByBookID(int bookID);

    @Delete("delete from book where bookID = #{bookID}")
    public int deleteBookByBookId(int bookID);

    @Update("update book set custNum =#{custNum},roomID =#{roomID}," +
            "createTime =#{createTime},arriveDate =#{arriveDate},leaveDate =#{leaveDate},remark =#{remark} where bookID =#{bookID} ")
    public int updateBookByBookID(int bookID, String custNum, int roomID, Date createTime, String arriveDate, String leaveDate, String remark);

    @Update("update book set bookState =#{bookState} where bookID =#{bookID} ")
    public int updateBookStateByBookId(int bookState,int bookID);


    //日期选择
    @Select("select * from book where arriveDate>=#{arriveDate} and leaveDate<=#{leaveDate} and typeID=#{typeID}")
    public  List<Book> findByDate(Map map);
    @Select("select * from book where arriveDate<=#{arriveDate} and leaveDate>=#{leaveDate} and typeID=#{typeID}")
    public  List<Book> findByDate1(Map map);
    @Select("select * from book where arriveDate>#{arriveDate} and arriveDate<#{leaveDate} and leaveDate>#{leaveDate} and typeID=#{typeID}")
    public  List<Book> findByDate2(Map map);
    @Select("select * from book where arriveDate<#{arriveDate} and leaveDate>#{arriveDate} and leaveDate<#{leaveDate} and typeID=#{typeID}")
    public   List<Book> findByDate3(Map map);

    @Insert(" insert into book (typeID,out_trade_no,money,custID,custNum,custPhone,arriveDate,leaveDate,remark,createTime,bookState) values(#{typeID},#{out_trade_no},#{money},#{custID},#{custNum},#{custPhone},#{arriveDate},#{leaveDate},#{remark},#{createTime},#{bookState})")
    public  int addCustBook(Book book);

    @Select("select * from book where custID=#{custID}")
    public  List<Book> findByAll(int  custID);

    @Select("select * from book where custID=#{custID} ")
    public List<Book> findByBook(int  custID);

    @Select("SELECT `user`.email from book,customer,`user` \n" +
            "where book.custNum=customer.custNum and customer.uID=`user`.uID and  bookID =#{bookID} ;")
    public String getBookEmail(String bookID);


    @Select("SELECT customer.custName from book,customer where book.custNum=customer.custNum and  bookID =#{bookID};")
    public String getBookCustName(String bookID);

    @Delete("DELETE from book where out_trade_no=#{out_trade_no}")
    public int deleteBook(String out_trade_no);




    //---------------------------------------------------------------查询订单

    @Select("select *  from book where arriveDate>=#{start} and leaveDate<=#{end} and bookState=#{option} and custNum=#{custNum}")
    public List<Book> getBooksBySEOC(String arriveDate, String leaveDate, String bookState, String custNum);

    @Select("select *  from book where  leaveDate<=#{end} ")
    public List<Book> getBooksByE(String end);

    @Select("select *  from book where arriveDate>=#{start}")
    public  List<Book> getBooksByS(String start);

    @Select("select *  from book where arriveDate>=#{start} and leaveDate<=#{end} ")
    public List<Book> getBooksBySE(String start, String end);

    @Select("select *  from book where  bookState=#{option} ")
    public List<Book> getBooksByO(String option);

    @Select("select *  from book where leaveDate<=#{end} and bookState=#{option} ")
    public List<Book> getBooksByOE(String end, String option);

    @Select("select *  from book where arriveDate>=#{start} and bookState=#{option}")
    public List<Book> getBooksBySO(String start, String option);

    @Select("select *  from book where arriveDate>=#{start} and leaveDate<=#{end} and bookState=#{option} ")
    public  List<Book> getBooksBySEO(String start, String end, String option);

    @Select("select *  from book where  custNum=#{custNum}")
    public   List<Book> getBooksByC(String custNum);

    @Select("select *  from book where leaveDate<=#{end} and custNum=#{custNum}")
    public  List<Book> getBooksByEC(String end, String custNum);

    @Select("select *  from book where arriveDate>=#{start} and custNum=#{custNum}")
    public  List<Book> getBooksBySC(String start, String custNum);

    @Select("select *  from book where arriveDate>=#{start} and leaveDate<=#{end}  and custNum=#{custNum}")
    public List<Book> getBooksBySEC(String custNum, String start, String end);

    @Select("select *  from book where bookState=#{option} and custNum=#{custNum}")
    public  List<Book> getBooksByOC(String option, String custNum);

    @Select("select * from book where  leaveDate<=#{end} and bookState=#{option} and custNum=#{custNum}")
    public  List<Book> getBooksByEOC(String end, String option, String custNum);
    @Select("select *  from book where arriveDate>=#{start}  and bookState=#{option} and custNum=#{custNum}")
    public List<Book> getBooksBySOC(String start, String custNum, String option);


    //---------------------------------------------------------------查询订单

}
